﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:AC.AvalonControlsLibrary.Controls">
    
    <Style TargetType="{x:Type local:TimePicker}">
        <Setter Property="MinWidth" Value="120"/>
        <Setter Property="MinHeight" Value="30"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:TimePicker}">
                    <!--Border that wraps the control-->
                    <Border Height="30" Width="120" 
                            Background="{TemplateBinding Background}"
                            CornerRadius="5" 
                            BorderBrush="{TemplateBinding BorderBrush}" 
                            BorderThickness="{TemplateBinding BorderThickness}" 
                            Padding="5">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="8*"/>
                                <ColumnDefinition Width="2*"/>
                            </Grid.ColumnDefinitions>

                            <Grid Height="20" 
                                  DataContext="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:TimePicker}}}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="23"/>
                                    <ColumnDefinition Width="5"/>
                                    <ColumnDefinition Width="23"/>
                                    <ColumnDefinition Width="5"/>
                                    <ColumnDefinition Width="23"/>
                                </Grid.ColumnDefinitions>

                                <Grid.Resources>
                                    <!--Control template to remove the default style of the textblock-->
                                    <Style TargetType="TextBlock" >
                                        <Setter Property="Foreground" Value="{Binding Foreground}"/>
                                        <Setter Property="FontWeight" Value="{Binding FontWeight}"/>
                                        <Setter Property="FontStyle" Value="{Binding FontStyle}"/>
                                        <Setter Property="FontStretch" Value="{Binding FontStretch}"/>
                                        <Setter Property="FontSize" Value="{Binding FontSize}"/>
                                        <Setter Property="FontFamily" Value="{Binding FontFamily}"/>
                                        <Setter Property="Margin" Value="0,0,0,2"/>
                                        <Setter Property="VerticalAlignment" Value="Center"/>
                                        <Setter Property="HorizontalAlignment" Value="Center"/>
                                    </Style>
                                    <!--Control template to remove the default style of the textboxes-->
                                    <Style TargetType="TextBox" >
                                        <!--Bind properties to use in the textboxes-->
                                        <Setter Property="Foreground" Value="{Binding Foreground}"/>
                                        <Setter Property="FontWeight" Value="{Binding FontWeight}"/>
                                        <Setter Property="FontStyle" Value="{Binding FontStyle}"/>
                                        <Setter Property="FontStretch" Value="{Binding FontStretch}"/>
                                        <Setter Property="FontSize" Value="{Binding FontSize}"/>
                                        <Setter Property="FontFamily" Value="{Binding FontFamily}"/>
                                        <Setter Property="VerticalAlignment" Value="Center"/>
                                        <Setter Property="HorizontalAlignment" Value="Center"/>
                                    </Style>
                                </Grid.Resources>

                                <!--Hour text-->
                                <TextBox Grid.Column="0" Name="PART_Hours" Text="{Binding SelectedHour}">
                                    <TextBox.Template>
                                        <ControlTemplate TargetType="TextBox">
                                            <ScrollViewer Name="PART_ContentHost"/>
                                        </ControlTemplate>
                                    </TextBox.Template>
                                </TextBox>
                                <TextBlock Text=":" Grid.Column="1"/>
                                <!--minute text-->
                                <TextBox Grid.Column="2" Name="PART_Minutes" Text="{Binding SelectedMinute}">
                                    <TextBox.Template>
                                        <ControlTemplate TargetType="TextBox">
                                            <ScrollViewer Name="PART_ContentHost"/>
                                        </ControlTemplate>
                                    </TextBox.Template>
                                </TextBox>
                                <TextBlock Text=":" Grid.Column="3"/>
                                <!--seconds text-->
                                <TextBox Grid.Column="4" Name="PART_Seconds" Text="{Binding SelectedSecond}">
                                    <TextBox.Template>
                                        <ControlTemplate TargetType="TextBox">
                                            <ScrollViewer Name="PART_ContentHost"/>
                                        </ControlTemplate>
                                    </TextBox.Template>
                                </TextBox>
                            </Grid>

                            <Grid Grid.Column="1" Height="20" Width="20">
                                <Grid.RowDefinitions>
                                    <RowDefinition/>
                                    <RowDefinition/>
                                </Grid.RowDefinitions>

                                <Button Name="PART_IncreaseTime" Height="10">
                                    <Button.Template>
                                        <ControlTemplate TargetType="Button">
                                                <Path Name="path" Fill="Silver" Data="M 5,10 L 15,10 L 10,5 L 5,10" 
                                                      Width="10" Height="8" 
                                                      Stretch="Fill"/>
                                            <ControlTemplate.Triggers>
                                                <Trigger Property="IsMouseOver" Value="true">
                                                    <Setter TargetName="path" Property="Fill" Value="Black"/>
                                                </Trigger>
                                            </ControlTemplate.Triggers>
                                        </ControlTemplate>
                                    </Button.Template>
                                </Button>
                                <Button Name="PART_DecrementTime" Grid.Row="1" Height="10">
                                    <Button.Template>
                                        <ControlTemplate TargetType="Button">
                                            <Path Name="path" Fill="Silver" Data="M 5,5 L 10,10 L 15,5 L 5,5" 
                                                      Width="10" Height="8" 
                                                      Stretch="Fill"/>
                                            <ControlTemplate.Triggers>
                                                <Trigger Property="IsMouseOver" Value="true">
                                                    <Setter TargetName="path" Property="Fill" Value="Black"/>
                                                </Trigger>
                                            </ControlTemplate.Triggers>
                                        </ControlTemplate>
                                    </Button.Template>
                                </Button>
                            </Grid>

                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>